package org.soderiakelvy.model.dao.imp;

import java.io.Serializable;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Order;
import org.soderiakelvy.model.dao.CondicionIvaDao;
import org.soderiakelvy.model.domain.CondicionIvaVO;
import org.soderiakelvy.model.domain.TipoClienteVO;
import org.soderiakelvy.model.util.HibernateUtil;

public class CondicionIvaDaoImp implements CondicionIvaDao, Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public void insertCondicionIvaVO(CondicionIvaVO condicionIva)
			throws Exception {
		SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
		Session session = sessionFactory.openSession();
		session.beginTransaction();
		session.save(condicionIva);
		session.getTransaction().commit();
		session.close();
	}

	@Override
	public void deleteCondicionIvaVO(CondicionIvaVO condicionIva)
			throws Exception {
		SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
		Session session = sessionFactory.openSession();
		session.beginTransaction();
		session.delete(condicionIva);
		session.getTransaction().commit();
		session.close();

	}

	@Override
	public void updateCondicionIvaVO(CondicionIvaVO condicionIva)
			throws Exception {
		SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
		Session session = sessionFactory.openSession();
		session.beginTransaction();
		session.update(condicionIva);
		session.getTransaction().commit();
		session.close();
	}

	@Override
	public List<CondicionIvaVO> getAllCondicionIva() throws Exception {		
		SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
        Session session = sessionFactory.openSession();
        Criteria criteria = session.createCriteria(CondicionIvaVO.class);
        criteria.addOrder(Order.asc("nombre"));
        List<CondicionIvaVO> ci = criteria.list();
        session.close();
        return ci;
	}
}
